package com.hjm.project.agentDateCen.agentDateCen.controller;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.hjm.common.exception.BusinessException;
import com.hjm.common.utils.ExportExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.agentDateCen.agentDateCen.domain.AgentDateCen;
import com.hjm.project.agentDateCen.agentDateCen.service.IAgentDateCenService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 服务商数据统计Controller
 * 
 * @author mark
 * @date 2020-12-04
 */
@Controller
@RequestMapping("/agentDateCen/agentDateCen")
public class AgentDateCenController extends BaseController
{
    private String prefix = "agentDateCen/agentDateCen";

    @Autowired
    private IAgentDateCenService agentDateCenService;

    @RequiresPermissions("agentDateCen:agentDateCen:view")
    @GetMapping()
    public String agentDateCen()
    {
        return prefix + "/agentDateCen";
    }

    /**
     * 查询服务商数据统计列表
     */
    @RequiresPermissions("agentDateCen:agentDateCen:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentDateCen agentDateCen)
    {
        startPage();
        List<AgentDateCen> list = agentDateCenService.selectAgentDateCenList(agentDateCen);
        return getDataTable(list);
    }

    /**
     * 导出服务商数据统计列表
     */
    @RequiresPermissions("agentDateCen:agentDateCen:export")
    @Log(title = "服务商数据统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentDateCen agentDateCen)
    {
        List<AgentDateCen> list = agentDateCenService.selectAgentDateCenList(agentDateCen);
        ExcelUtil<AgentDateCen> util = new ExcelUtil<AgentDateCen>(AgentDateCen.class);
        return util.exportExcel(list, "agentDateCen");
    }

    /**
     * 新增服务商数据统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服务商数据统计
     */
    @RequiresPermissions("agentDateCen:agentDateCen:add")
    @Log(title = "服务商数据统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentDateCen agentDateCen)
    {
        return toAjax(agentDateCenService.insertAgentDateCen(agentDateCen));
    }

    /**
     * 修改服务商数据统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AgentDateCen agentDateCen = agentDateCenService.selectAgentDateCenById(id);
        mmap.put("agentDateCen", agentDateCen);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务商数据统计
     */
    @RequiresPermissions("agentDateCen:agentDateCen:edit")
    @Log(title = "服务商数据统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentDateCen agentDateCen)
    {
        return toAjax(agentDateCenService.updateAgentDateCen(agentDateCen));
    }

    /**
     * 删除服务商数据统计
     */
    @RequiresPermissions("agentDateCen:agentDateCen:remove")
    @Log(title = "服务商数据统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(agentDateCenService.deleteAgentDateCenByIds(ids));
    }



    /**
     * 前往活跃商户页面
     */
    @RequiresPermissions("agentDateCen:agentDateCen:view")
    @GetMapping("/hyMer")
    public String hyMer()
    {
        return prefix + "/hyMer";
    }

    /**
     * 活跃商户
     */
    @RequiresPermissions("agentDateCen:agentDateCen:list")
    @PostMapping("/hyMerList")
    @ResponseBody
    public TableDataInfo hyMerList(AgentDateCen agentDateCen)
    {
        startPage();
        agentDateCen.setType(Long.parseLong("2"));
        List<AgentDateCen> list = agentDateCenService.selectAgentDateCenList(agentDateCen);
        return getDataTable(list);
    }



    /**
     * 前往未实名商户页面
     */
    @RequiresPermissions("agentDateCen:agentDateCen:view")
    @GetMapping("/noSm")
    public String noSm()
    {
        return prefix + "/noSm";
    }

    /*

    *//**
     * 未实名商户
     *//*
    @RequiresPermissions("agentDateCen:agentDateCen:list")
    @PostMapping("/noSmList")
    @ResponseBody
    public TableDataInfo noSmList(AgentDateCen agentDateCen)
    {
        startPage();
        List<AgentDateCen> list = agentDateCenService.selectAgentDateCenList(agentDateCen);
        return getDataTable(list);
    }*/



    /**
     * 前往沉默商户
     */
    @RequiresPermissions("agentDateCen:agentDateCen:view")
    @GetMapping("/cm")
    public String cm()
    {
        return prefix + "/cm";
    }

   /* *//**
     * 沉默商户
     *//*
    @RequiresPermissions("agentDateCen:agentDateCen:list")
    @PostMapping("/cmList")
    @ResponseBody
    public TableDataInfo cmList(AgentDateCen agentDateCen)
    {
        startPage();
        List<AgentDateCen> list = agentDateCenService.selectAgentDateCenList(agentDateCen);
        return getDataTable(list);
    }*/





    @RequiresPermissions("agentDateCen:agentDateCen:silentMerByMonth")
    @GetMapping("/silentMerByMonth")
    public String silentMerByMonth()
    {
        return prefix + "/silentMerByMonth";
    }

    /**
     * 沉默商户按月数据统计
     */
    @RequiresPermissions("agentDateCen:agentDateCen:silentMerByMonth")
    @PostMapping("/silentMerByMonth")
    @ResponseBody
    public TableDataInfo silentMerByMonth(@RequestParam Map<String,Object> params)
    {
        startPage();
        List<Map<String,Object>> list = agentDateCenService.selectSilentMerByMonth(params);
        return getDataTable(list);
    }
    @RequiresPermissions("agentDateCen:agentDateCen:exportByMonth")
    @Log(title = "沉默商户按月数据统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportByMonth")
    @ResponseBody
    public AjaxResult exportByMonth(@RequestParam Map<String,Object> params)
    {
        try {
            List<Map<String,Object>> list = agentDateCenService.selectSilentMerByMonth(params);
            LinkedHashMap<String, String> titleMap = new LinkedHashMap<>();
            titleMap.put("MER_SILENT_NUM", "沉默商户数");
            titleMap.put("BELONG_DATE", "月份");
            String fileName = "沉默商户按月数据统计.xlsx";
            ExportExcelUtil.exportExcel(fileName, list, titleMap, "");
            return AjaxResult.success(fileName);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("导出Excel失败，请联系网站管理员！");
        }

    }

    @RequiresPermissions("agentDateCen:agentDateCen:silentMerByMonthAndAgent")
    @GetMapping("/silentMerByMonthAndAgent")
    public String silentMerByMonthAndAgent()
    {
        return prefix + "/silentMerByMonthAndAgent";
    }

    /**
     * 查询服务商数据统计列表
     */
    @RequiresPermissions("agentDateCen:agentDateCen:silentMerByMonthAndAgent")
    @PostMapping("/silentMerByMonthAndAgent")
    @ResponseBody
    public TableDataInfo silentMerByMonthAndAgent(@RequestParam Map<String,Object> params)
    {
        startPage();
        List<Map<String,Object>> list = agentDateCenService.selectSilentMerByMonthAndAgent(params);
        return getDataTable(list);
    }
    @RequiresPermissions("agentDateCen:agentDateCen:exportByMonthAndAgent")
    @Log(title = "沉默商户按月数按服务商据统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportByMonthAndAgent")
    @ResponseBody
    public AjaxResult exportByMonthAndAgent(@RequestParam Map<String,Object> params)
    {
        try {
            List<Map<String,Object>> list = agentDateCenService.selectSilentMerByMonthAndAgent(params);
            LinkedHashMap<String, String> titleMap = new LinkedHashMap<>();
            titleMap.put("AGENT_NUM", "服务商编号");
            titleMap.put("AGENT_NAME", "服务商名称");
            titleMap.put("MER_SILENT_NUM", "沉默商户数");
            titleMap.put("BELONG_DATE", "月份");
            String fileName = "沉默商户按月数按服务商据统计.xlsx";
            ExportExcelUtil.exportExcel(fileName, list, titleMap, "");
            return AjaxResult.success(fileName);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("导出Excel失败，请联系网站管理员！");
        }

    }

    @RequiresPermissions("agentDateCen:agentDateCen:activeMerByMonth")
    @GetMapping("/activeMerByMonth")
    public String activeMerByMonth()
    {
        return prefix + "/activeMerByMonth";
    }

    /**
     * 活跃商户按月数据统计
     */
    @RequiresPermissions("agentDateCen:agentDateCen:activeMerByMonth")
    @PostMapping("/activeMerByMonth")
    @ResponseBody
    public TableDataInfo activeMerByMonth(@RequestParam Map<String,Object> params)
    {
        startPage();
        List<Map<String,Object>> list = agentDateCenService.selectActiveMerByMonth(params);
        return getDataTable(list);
    }
    @RequiresPermissions("agentDateCen:agentDateCen:exportByActMonth")
    @Log(title = "活跃商户按月数据统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportByActMonth")
    @ResponseBody
    public AjaxResult exportByActMonth(@RequestParam Map<String,Object> params)
    {
        try {
            List<Map<String,Object>> list = agentDateCenService.selectActiveMerByMonth(params);
            LinkedHashMap<String, String> titleMap = new LinkedHashMap<>();
            titleMap.put("MER_ACTIVE_NUM", "活跃商户数");
            titleMap.put("BELONG_DATE", "月份");
            String fileName = "活跃商户按月数据统计.xlsx";
            ExportExcelUtil.exportExcel(fileName, list, titleMap, "");
            return AjaxResult.success(fileName);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("导出Excel失败，请联系网站管理员！");
        }

    }

    @RequiresPermissions("agentDateCen:agentDateCen:activeMerByMonthAndAgent")
    @GetMapping("/activeMerByMonthAndAgent")
    public String activeMerByMonthAndAgent()
    {
        return prefix + "/activeMerByMonthAndAgent";
    }

    /**
     * 查询服务商数据统计列表
     */
    @RequiresPermissions("agentDateCen:agentDateCen:activeMerByMonthAndAgent")
    @PostMapping("/activeMerByMonthAndAgent")
    @ResponseBody
    public TableDataInfo activeMerByMonthAndAgent(@RequestParam Map<String,Object> params)
    {
        startPage();
        List<Map<String,Object>> list = agentDateCenService.selectActiveMerByMonthAndAgent(params);
        return getDataTable(list);
    }
    @RequiresPermissions("agentDateCen:agentDateCen:exportActByMonthAndAgent")
    @Log(title = "活跃商户按月数按服务商据统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportActByMonthAndAgent")
    @ResponseBody
    public AjaxResult exportActByMonthAndAgent(@RequestParam Map<String,Object> params)
    {
        try {
            List<Map<String,Object>> list = agentDateCenService.selectActiveMerByMonthAndAgent(params);
            LinkedHashMap<String, String> titleMap = new LinkedHashMap<>();
            titleMap.put("AGENT_NUM", "服务商编号");
            titleMap.put("AGENT_NAME", "服务商名称");
            titleMap.put("MER_ACTIVE_NUM", "活跃商户数");
            titleMap.put("BELONG_DATE", "月份");
            String fileName = "活跃商户按月数按服务商据统计.xlsx";
            ExportExcelUtil.exportExcel(fileName, list, titleMap, "");
            return AjaxResult.success(fileName);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("导出Excel失败，请联系网站管理员！");
        }

    }
}
